package com.example.springboot.service;

import java.util.List;

import javax.annotation.Resource;

import com.example.springboot.bean.PageResult;
import com.example.springboot.bean.User;
import com.example.springboot.repository.UserRepository;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

@Service
public class UserService implements UserRepository{
	@Resource
	private UserRepository userRepository;
	@Resource
	private MailService mailService;

	public int insertUser(User user) {
		return userRepository.insertUser(user);
	}
	
	public void insertGetKey(User user) {
		userRepository.insertGetKey(user);
	}
	
	public User selectByUsername(String username) {
		return userRepository.selectByUsername(username);
	}


	public List<User> findAll(){
		return userRepository.findAll();
	}

	@Override
	public User findUserById(int id) {
		return userRepository.findUserById(id);
	}

	public void update(User user) {
		userRepository.update(user);
	}


	public PageResult findPage(Integer pageNum, Integer pageSize) {
		PageHelper.startPage(pageNum,pageSize);
		List<User> list = userRepository.findAll();
        PageInfo<User> pageInfo = new PageInfo<>(list);
        return new PageResult(pageInfo.getTotal(),pageInfo.getList());
	}

	@Override
	public void dele(long[] ids) {
		for (long id : ids){
			userRepository.delete(id);
		}
	}

	public void delete(long id) {
		userRepository.delete(id);
	}




}
